package com.isias.system.service.Impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isias.model.El.ElQu;
import com.isias.model.dto.RepoAndIdDto;
import com.isias.model.vo.ElQuQueryVo;
import com.isias.system.mapper.ElQuMapper;
import com.isias.system.service.ElQuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class ElQuServiceImpl extends ServiceImpl<ElQuMapper, ElQu> implements ElQuService {

    @Autowired
    private ElQuMapper elQuMapper;


    @Override
    public IPage<ElQu> SeletePage(Page<ElQu> pageparam, ElQuQueryVo elQuQueryVo) {
        if (elQuQueryVo.getRepoId() == null || elQuQueryVo.getRepoId().isEmpty()){
            return elQuMapper.SeletePageOrdinary(pageparam, elQuQueryVo);
        }
        return elQuMapper.SeletePage(pageparam, elQuQueryVo);
    }

    @Override
    public boolean AddQuToRepo(String repoId, String quId) {
        if (elQuMapper.findIdByRepoIdAndQuId(repoId,quId) > 0){
            return false;
        }
        return elQuMapper.AddQuToRepo(repoId,quId)>0;
    }

    @Override
    public boolean DeleteQuToRepo(String repoId, String quId) {
        return elQuMapper.DeleteQuToRepo(repoId,quId)>0;
    }

    @Override
    public boolean DeleteQusToRepo(String repoId, List<String> idList) {
        return elQuMapper.DeleteQusToRepo(repoId,idList)>0;
    }

    @Override
    public List<RepoAndIdDto> GetRepoAndId() {
        return elQuMapper.GetRepoAndId();
    }

    @Override
    public List<ElQu> SeleteAll(ElQuQueryVo elQuQueryVo) {
        return elQuMapper.SeleteAll(elQuQueryVo);
    }
}
